package com.EVO.controller;

import com.EVO.dao.QueryDao;
import com.EVO.entity.Province;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class QueryProviceServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        QueryDao dao = new QueryDao();
        List<Province> provinceList = dao.queryProviceList();
        String json = "{}";
        PrintWriter out = null;
        if(provinceList != null){
            ObjectMapper om = new ObjectMapper();
            json = om.writeValueAsString(provinceList);
        }

        response.setContentType("application/json;charset=utf-8");
        out = response.getWriter();
        out.print(json);
    }
}
